package cn.NewsServlet;

import cn.NewsDao.NewsDao1;
import cn.NewsDao.NewsDao4;
import cn.NewsDaoImpl.NewsDaoImpl1;
import cn.NewsDaoImpl.NewsDaoImpl4;
import cn.NewsService.NewsService;
import cn.NewsServiceImpl.NewsServiceImpl;
import cn.entity.News4;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;



@WebServlet("/deng")
public class dengServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String name=req.getParameter("username");
        String pass = req.getParameter("password");
        NewsDao4 newsDao1 = new NewsDaoImpl4();
        List<News4> newsList = newsDao1.getNewsList();
        resp.setContentType("text/html;charset=utf-8");
        PrintWriter printWriter=resp.getWriter();
        News4 news4 = new News4(name,pass);
        String mag="1";
        /*if (news4.getPassword() !=null&&news4.getUserName()!=null){
            mag="登录";
        }else {
            mag="失败";
        }*/
        for (int i=0;i<newsList.size();i++){
            if (newsList.get(i).getUserName().equals(name)&&newsList.get(i).getPassword().equals(pass)){
                mag="1";
                break;

            }else {
                mag="0";
            }
        }
        //resp.setCharacterEncoding("text/html;charset=UTF-8");
        printWriter.println(mag);


        printWriter.flush();
        printWriter.close();



    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println(12321323);




    }
}
